package com.wgj.android.dialog;

import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.google.gson.Gson;
import com.jiaai.xui.XUI;
import com.jiaai.xui.cache.XCache;
import com.jiaai.xui.icon.utils.IconUtils;
import com.jiaai.xui.utils.XBitmapUtils;
import com.jiaai.xui.utils.XDensityUtils;
import com.jiaai.xui.utils.XEmptyUtils;
import com.jiaai.xui.utils.XPreferencesUtils;

import com.jiaai.xui.utils.log.XLog;
import com.jiaai.xui.utils.share.ShareUtils;
import com.jiaai.xui.utils.share.dialog.ShareDialog;
import com.jiaai.xui.utils.share.entity.Share;
import com.jiaai.xui.view.widget.MultiStatusBut;
import com.jiaai.xui.view.widget.XToast;
import com.wgj.android.R;
import com.wgj.android.entity.Member;
import com.wgj.android.entity.SystemConfg;
import com.wgj.android.events.PayEvents;
import com.wgj.android.utils.CacheUtils;
import com.wgj.android.utils.TextViweUtils;
import com.wgj.android.utils.fonat.IconFonat;

import org.greenrobot.eventbus.EventBus;

import java.io.ByteArrayOutputStream;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/4.
 */

public class ShareDiadlog extends DialogFragment {
    private Dialog dialog ;
    private View view;


    @BindView(R.id.shareWeiXinBut)
    TextView shareWeiXinBut;
    @BindView(R.id.shareQQBut)
    TextView shareQQBut;
    @BindView(R.id.shareSpaceBut)
    TextView shareSpaceBut;
    @BindView(R.id.shareFriendsBut)
    TextView shareFriendsBut;

    @BindView(R.id.linkBut)
    TextView linkBut;

    private  OnShareListener onShareListener;
    @Nullable
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        if(dialog==null){
            // 使用不带Theme的构造器, 获得的dialog边框距离屏幕仍有几毫米的缝隙。
            initDialogStyle(view);
        }
        return dialog;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if(view==null){
            super.onCreate(savedInstanceState);
            view = LayoutInflater.from(getActivity()).inflate(R.layout.share_dialog, null, false);
        }
        ButterKnife.bind(this,view);
        TextViweUtils.setDrawableTop(shareQQBut,IconFonat.Icon.icon_qq,XUI.getColor(R.color.primary_text) ,8);
        TextViweUtils.setDrawableTop(shareSpaceBut,IconFonat.Icon.icon_qqkongjian,XUI.getColor(R.color.primary_text) ,8);
        TextViweUtils.setDrawableTop(shareWeiXinBut,IconFonat.Icon.icon_weixin,XUI.getColor(R.color.primary_text) ,8);
        TextViweUtils.setDrawableTop(shareFriendsBut,IconFonat.Icon.icon_pengyouquan,XUI.getColor(R.color.primary_text) ,8);
        TextViweUtils.setDrawableTop(linkBut,IconFonat.Icon.icon_lianjie,XUI.getColor(R.color.primary_text) ,8);

    }

    private void initDialogStyle(View view) {
        dialog = new Dialog(getActivity(), R.style.dialog_setting);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
        dialog.setContentView(view);
        dialog.setCanceledOnTouchOutside(true); // 外部点击取消
        // 设置宽度为屏宽, 靠近屏幕底部。
        Window window = dialog.getWindow();
        window.setWindowAnimations(R.style.popupwindow_anim_style);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM; // 紧贴底部
        lp.width = XDensityUtils.getScreenWidth()-XDensityUtils.dp2px(20);
        window.setAttributes(lp);
    }

    @OnClick({R.id.shareWeiXinBut,R.id.shareFriendsBut,R.id.shareQQBut,R.id.shareSpaceBut,R.id.linkBut}) void  onShareWeiXin(View view){
        Member member= CacheUtils.getMember();


        switch (view.getId()){
            case R.id.shareWeiXinBut:
                if(onShareListener!=null){
                    onShareListener.onShareWeiXin();
                }


                break;
            case R.id.shareFriendsBut:
                if(onShareListener!=null){
                    onShareListener.onShareFriends();
                }
                break;
                case R.id.shareQQBut:
                    if(onShareListener!=null){
                        onShareListener.onShareQQ();
                    }
                    XToast.error("暂未开放");
                    break;
            case R.id.shareSpaceBut:
                    if(onShareListener!=null){
                        onShareListener.onShareSpaceBut();
                    }
                  break;
            case R.id.linkBut:
                if(onShareListener!=null){
                    onShareListener.onlinkButBut();
                }
                break;
        }
    }


    public ShareDiadlog setOnShareListener(OnShareListener onShareListener) {
        this.onShareListener = onShareListener;
        return this;
    }

    public  interface  OnShareListener{
        void  onShareQQ();
        void  onShareWeiXin();
        void  onShareFriends();
        void  onShareSpaceBut();
        void  onlinkButBut();
    }
}
